// Skyeye wrapper implementation
// wrap operations on skeyey simulator

#ifndef ETB_SKYEYE_IMPL_H_
#define ETB_SKYEYE_IMPL_H_

#include <string>
#include <vector>
#include "Config.h"
#include "skyeye/skyeye_arch.h"

namespace etb {

  class SkyeyeCallback
  {
  public:
    virtual void handleCallback(const std::string type, 
                                const std::string event) = 0;
  };

  // SkyeyeImpl
  // Singleton class
  class SkyeyeImpl
  {

  // constructors and destructors
  public:
    ~SkyeyeImpl();
  private:
    SkyeyeImpl() {}

  public:
    static const U32 LCDSADDR1  = 0x4D000014;
    static const U32 GPGDAT     = 0x56000064;
    static const U32 GPBDAT     = 0x56000014;

  // public api
  public:
    static SkyeyeImpl* getInst() {
      if (!impl_)
        impl_ = new SkyeyeImpl();

      return impl_;
    }

    void setCallback(SkyeyeCallback* cb) {
      cb_ = cb;
    }

    SkyeyeCallback* getCallback() { 
      return cb_; 
    }

    U32 getLcdBaseAddr();

    static void busWriteCallback(generic_arch_t* arch_instance);
    static void setBit32(U32 *data, U8 value, U8 offset);

    void initMach();
    U32  getInstruction();
    U32  writeToMemory(U8 *ptr, U32 addr, U32 size);
    void setPc(U32 addr);
    void runMach();
    void stopMach();
    void pauseMach();
    void stepRun();
    void continueMach();
    void dumpRegs(std::vector<U32>& regs);
    void keyPressed(int keyNum);
    void keyReleased(int keyNum);

  // inherited api
  public:

  // private methods
  private:

  // private members
  private:
    static SkyeyeImpl*    impl_;
    SkyeyeCallback*       cb_;
  };

}

#endif  // ETB_SKYEYE_IMPL_H_
